package 贪心算法;

import java.lang.reflect.Array;
import java.util.Arrays;

public class 分发饼干 {
    //思路1：优先考虑饼干，小饼干先喂饱小胃口
    class Solution1{
        //这里的g[]是胃口值，s[]是饼干大小值
        public int findContentChildren(int[] g,int[] s){
            Arrays.sort(g);
            Arrays.sort(s);
            int start = 0;
            int count = 0;
            for (int i = 0; i < s.length && start<g.length; i++) {
                if (s[i]>=g[start]){
                    start++;
                    count++;
                }

            }
            return count;
        }

    }
    //思路2：优先考虑大胃口，先喂饱大胃口
    class Solution2{
        public int findContentChildren(int[] g,int[] s){
            Arrays.sort(g);
            Arrays.sort(s);
            int count = 0;
            int start = s.length -1 ;
            for (int index = g.length -1; index >= 0; index--) {
               if (start>=0&&s[start]>=g[index]){
                   start--;
                   count++;
               }

            }
            return count;
        }
    }
}
